package com.study.eventbus;

import com.google.common.eventbus.EventBus;
import com.sun.jmx.snmp.UserAcl;

/**
 * 创建人： HBZ，时间： 2017/8/18 11:32.
 * 说明：
 */
public class Test {
    public static void main(String[] args) throws InterruptedException {

        DataObserver1 observer1 = new DataObserver1();
        DataObserver2 observer2 = new DataObserver2();

        EventBusCenter.register(observer1);
        EventBusCenter.register(observer2);

        System.out.println("============   start  ====================");

        // 只有注册的参数类型为String的方法会被调用
        EventBusCenter.post("post string method");
        EventBusCenter.post(123);

        System.out.println("============ after unregister ============");
        // 注销observer2
        EventBusCenter.unregister(observer2);
        EventBusCenter.post("post string method");
        EventBusCenter.post(123);
        EventBus a=new EventBus("test");
        System.out.println("============    end           =============");

        DataObserver3 dataObserver3=new DataObserver3();
        TestUser user=new TestUser();
        user.setName("defaultMethod");
        EventBusCenter.register(dataObserver3);
        EventBusCenter.post(user);
    }
}
